package com.devinlee.designpatterns.proxy.dynamicproxy;

import com.devinlee.designpatterns.proxy.RealSubject;
import com.devinlee.designpatterns.proxy.Subject;

import java.lang.reflect.Proxy;

/**
 * 动态代理-测试
 */
public class Demo {

    public static void main(String[] args) {

        // 真实对象
        Subject realSubject = new RealSubject();
        // 编制AOP
        Interceptor myInterceptor = new MyInterceptor();
        // JDK动态代理对象
        Subject proxySubject = (Subject) Proxy.newProxyInstance(realSubject.getClass().getClassLoader(), realSubject.getClass().getInterfaces(), new MyInvocationHandler(myInterceptor, realSubject));
        // 增强访问
        proxySubject.todo();
    }
}
